<template>
  <div class="passenger-station-right">
    <nanning-screen-border-box :bgImg="bgImg">
      <screen-title>查询列表</screen-title>
      <div class="passenger-station-right-content">
        <nanning-screen-search placeholder-value="请输入公交公司、线路、案件类型" :value="searchValue" @on-input-search="inputSearch" @on-click-search="onSearch"></nanning-screen-search>
        <!-- <div class="total-num">共152条数据</div> -->
        <div class="query-list">
          <div v-if="style == '0'">
            <div :class="['list-item', currentItem === index ? 'active' : '']" v-for="(item, index) in queryList" :key="index" @click="chooseItem(index)">
              <div class="station">{{item.station}}</div>
              <div class="station-info">
                <div class="sub-text">途径客车：</div>
                  <div class="detail">
                    <div class="detail-item" v-for="(detail, order) in item.detailList" :key="order">
                      <div class="value">{{detail.from}} → {{detail.to}}</div>
                    </div>
                  </div>
              </div>
            </div>
          </div>
          <div v-else-if="style == '1'">
            <div :class="['list-item', currentItem === index ? 'active' : '']" v-for="(item, index) in queryList" :key="index" @click="chooseItem(index, item.id)">
              <div class="station">{{item.kyzmc}}</div>
              <div class="station-info">
                <div class="volume">今日客流量：<span>{{item.id}}次</span></div>
              </div>
            </div>
          </div>
          <div v-else-if="style == '2'">
            <div :class="['list-item', currentItem === index ? 'active' : '']" v-for="(item, index) in queryList2" :key="index" @click="chooseItem(index)">
              <div class="station">{{item.name}}</div>
              <div class="passenger-info">
                <div class="idcard"><span>身份证号：</span><span>{{item.idCard}}</span></div>
                <div class="time"><span>时&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;间：</span><span>{{item.time}}</span></div>
              </div>
            </div>
          </div>
          <screen-load-more :loadMoreVisible="loadMoreVisible" :loadMoreType="loadMoreType"></screen-load-more>
        </div>
      </div>
    </nanning-screen-border-box>
    <station-pop class="passenger-info-dialog" :station-pop-data="passengerInfo" title="旅客详情" v-if="visibleDialog" @close="closeDialog"></station-pop>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import stationPop from '../components/stationPop/index.vue'
import EventBus from '../../../../utils/eventBus'
import { getStationMap } from '@/api/situationAwareness/passengerStation/passengerStation'
enum LoadMoreType {
  none = 'none',
  loading = 'loading',
}
@Component({
  name: 'passenger-station-right',
  components: {
    stationPop
  }
})
export default class PassengerStationRight extends Vue {
  private bgImg: string = require('assets/images/situational-awareness/security-left-border.png')

  private currentItem: string | number = ''

  private loadMoreVisible = false
  private loadMoreType: LoadMoreType = LoadMoreType.none

  private style = '1'

  private queryList: any[] = [
    { station: '南宁汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] },
    { station: '桂林汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] },
    { station: '柳州汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] },
    { station: '北海汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] },
    { station: '玉林汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] },
    { station: '南宁汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] },
    { station: '青海汽车站', count: 22480, detailList: [{ from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }, { from: '南宁', to: '北海' }] }
  ]

  private queryList2: any[] = [
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' },
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' },
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' },
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' },
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' },
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' },
    { name: '由美', idCard: '375082199603202030', time: '2021-7-26 15:20:42' }
  ]

  private visibleDialog = false

  private passengerInfo = {
    realName: '张宁',
    idCard: '380262199603202302',
    buyTime: '2021-7-26 15:20:11',
    departureStation: '贵州',
    terminus: '柳州',
    company: '白马客运有限公司',
    vehicle: '桂A98650'
  }

  private pageIndex = 1

  private pageSize = 10

  private searchValue = ''

  private listTotal = 0

  private loadStatus = true

  mounted() {
    this.queryList = []
    this.onReachBottom()
    this.getStationMap()
  }

  beforeDestroy () {
    // @ts-ignore
    document.querySelector('.query-list').removeEventListener('scroll', this.queryListFunction)
  }

  onReachBottom() {
    // @ts-ignore
    document.querySelector('.query-list').addEventListener('scroll', this.queryListFunction)
  }

  queryListFunction (e: any) {
    console.log('onReachBottom', this.pageIndex, this.loadMoreType)
    if (this.loadMoreType === LoadMoreType.none) {
      return
    }
    const { scrollHeight, scrollTop, clientHeight } = e.target
    if (clientHeight + scrollTop >= scrollHeight) {
      this.loadMoreVisible = true
      this.pageIndex++
      this.getStationMap()
    }
  }

  // 选择客运站
  chooseItem(index: number, id: string) {
    this.currentItem = index
    // this.visibleDialog = true
    EventBus.$emit('chooseStation', { id: id, index: index })
  }

  // 关闭对话框
  closeDialog () {
    this.visibleDialog = false
  }

  // 输入搜索
  inputSearch (e: any) {
    this.searchValue = e
    if (this.searchValue === '') {
      this.queryList = []
      this.pageIndex = 1
      this.listTotal = 0
      this.getStationMap()
    }
  }
  // 搜索
  onSearch () {
    this.queryList = []
    this.pageIndex = 1
    this.listTotal = 0
    if (this.searchValue) {
      this.getStationMap()
    }
  }
  // 获取数据列表
  async getStationMap () {
    this.loadStatus = true
    EventBus.$emit('resetMarker')
    const params = {
      dzcode: ''
    }
    try {
      this.loadMoreType = LoadMoreType.loading
      const res: any = await getStationMap(params)
      this.queryList = [...this.queryList, ...res.data]
      // this.listTotal = res.data.total
      this.loadMoreType = res.data.length < this.pageSize ? LoadMoreType.none : LoadMoreType.loading
      this.loadStatus = false
      EventBus.$emit('queryList', this.queryList)
    } catch (err) {
      this.pageIndex = 1
      this.listTotal = 0
      this.loadMoreType = LoadMoreType.none
      this.loadStatus = false
      console.error(err)
    }
  }
}
</script>

<style lang="scss" scoped>
.passenger-station-right {
  box-sizing: border-box;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 1;
  width: 25.47%;
  height: 87.13%;
  animation: fadeInRight 0.7s linear;
  &-content {
    width: 100%;
    height: calc(100% - 50px);
    box-sizing: border-box;
    padding: 15px 24px 18px 22px;
    .total-num {
      width: 100%;
      height: 4em;
      line-height: 56px;
      font-size: 14px;
      font-family: 'PingFang Regular';
      font-weight: 400;
      color: rgba(255, 255, 255, 0.67);
      margin-top: 10px;
      text-indent: 20px;
    }
    .query-list {
      width: 100%;
      height: calc(100% - 42px - 10px - 56px);
      overflow-y: auto;
      &::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
        height: 1px;
      }
      &::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #114da7;
      }
      &::-webkit-scrollbar-track {
        /*滚动条里面轨道*/
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        background: #061836;
      }
      .list-item {
        width: 100%;
        box-sizing: border-box;
        padding: 0 20px;
        background: rgba(16, 75, 164, 0.22);
        border-radius: 2px;
        cursor: pointer;
        .station {
          width: 100%;
          height: 42px;
          display: flex;
          align-items: center;
          font-size: 18px;
          font-family: 'PingFang Regular';
          font-weight: 400;
          color: #ffffff;
          border-bottom: 1px dashed #8398d9;
        }
        .station-info {
          display: flex;
          .sub-text {
            font-size: 16px;
            font-family: 'PingFang Regular';
            font-weight: 400;
            color: rgba(255, 255, 255, 0.67);
            width: 25%;
            padding-top: 10px;
          }
          .volume {
            height: 42px;
            font-size: 16px;
            font-family: 'PingFang Regular';
            font-weight: 400;
            color: rgba(255, 255, 255, 0.67);
            width: 100%;
            padding-top: 10px;
            box-sizing: border-box;
            span {
              color: #98D9FF;
            }
          }
          .detail {
            width: 75%;
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            padding: 6px 0;
            .detail-item {
              width: 100%;
              line-height: 28px;
              display: flex;
              align-items: center;
              .label {
                font-size: 16px;
                font-family: 'PingFang Regular';
                font-weight: 400;
                color: rgba(255, 255, 255, 0.67);
              }
              .value {
                font-size: 16px;
                font-family: 'PingFang Regular';
                font-weight: 400;
                color: #8da5eb;
              }
            }
          }
        }
        .passenger-info {
          display: flex;
          flex-direction: column;
          .idcard {
            height: 32px;
            font-size: 16px;
            font-family: 'PingFang Regular';
            font-weight: 400;
            color: rgba(255, 255, 255, 0.67);
            width: 100%;
            padding-top: 10px;
            box-sizing: border-box;
            span:nth-child(1) {
              display: inline-block;
              width: 80px;
            }
            span:nth-child(2) {
              color: #98D9FF;
            }
          }
          .time {
            margin-bottom: 10px;
            height: 32px;
            font-size: 16px;
            font-family: 'PingFang Regular';
            font-weight: 400;
            color: rgba(255, 255, 255, 0.67);
            width: 100%;
            padding-top: 4px;
            box-sizing: border-box;
            span:nth-child(1) {
              display: inline-block;
              width: 80px;
            }
            span:nth-child(2) {
              color: #98D9FF;
            }
          }
        }
        & + .list-item {
          margin-top: 6px;
        }
        &.active {
          box-shadow: 0px 0px 15px 9px #2235b6 inset;
        }
      }
    }
  }
  .passenger-info-dialog {
    position: absolute;
    left: -300px;
    top: 50px;
    cursor: pointer;
  }
}
</style>
